package com.mallcloud.mall.app.controller;

import cn.hutool.core.lang.tree.Tree;
import com.mallcloud.mall.app.service.AppProductCategoryService;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.mall.api.entity.MallProductCategoryModel;
import com.mallcloud.mall.product.api.entity.CategoryModel;
import com.mallcloud.mall.product.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "商品分类管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/app/productCategory")
public class AppProductCategoryController {
    private final AppProductCategoryService appProductCategoryService;

    @ApiOperation("第一级商品分类")
    @GetMapping("/first")
    public R<List<CategoryModel>> first() {
        return R.ok(appProductCategoryService.getFrontFirstCategory());
    }

    @ApiOperation("第三级商品分类")
    @GetMapping("/third")
    public R<List<CategoryModel>> third(Long id) {
        return R.ok(appProductCategoryService.getHomeThirdCategory(id));
    }

    @ApiOperation("商户端分类缓存树")
    @GetMapping("/tree")
    public R<List<Tree<Long>>> tree() {
        return R.ok(appProductCategoryService.getMerchantCacheTree());
    }

}
